package com.shutuo.callnumtwofire.screeninfo;



import org.json.JSONArray;
import org.json.JSONObject;

public class ScreenInfoParser {

    private static JSONObject getSingleData(JSONObject json) {
        if (json == null) return null;
        JSONArray dataArray = json.optJSONArray("data");
        if (dataArray == null || dataArray.length() == 0) return null;
        return dataArray.optJSONObject(0);
    }

    public static TwofireInfo parseResult(JSONObject jsonObject) throws Throwable {
        JSONObject json = getSingleData(jsonObject);
        if (json == null) return null;

        long screenId = json.optLong("screen_id");
        JSONObject owner_shop = json.optJSONObject("owner_shop");
        TwofireInfo twofireInfo = null;

        if(owner_shop != null){
            long shop_id = owner_shop.optLong("shop_id");
            twofireInfo = new TwofireInfo(screenId,shop_id);

        }

        if(twofireInfo == null){
            twofireInfo = new TwofireInfo(0,0);
        }
        return twofireInfo;
    }

}
